/****************************************************************************************
 *
 * File Name: kf_it.c
 * Project Name: KF32A156
 * Version: v2.0
 * Date: 2021-05-17- 09:13:03
 * Author: dell
 * 
 ****************************************************************************************/
#include "system_init.h"
#include "kf32a1x6_canfd.h"
#include "Canfd.h"

extern uint32_t Receive_Flag;

//*****************************************************************************************
//                                 NMI Interrupt Course
//*****************************************************************************************	
void __attribute__((interrupt)) _NMI_exception (void)
{	

}

//*****************************************************************************************
//                               HardFault Interrupt Course
//*****************************************************************************************	

void __attribute__((interrupt)) _HardFault_exception (void)
{

}

//*****************************************************************************************
//                               StackFault Interrupt Course
//*****************************************************************************************	
void __attribute__((interrupt)) _StackFault_exception (void)
{

}

//*****************************************************************************************
//                               SVC Interrupt Course
//*****************************************************************************************	
void __attribute__((interrupt)) _SVC_exception (void)
{

}

//*****************************************************************************************
//                              SoftSV Interrupt Course
//*****************************************************************************************	
void __attribute__((interrupt)) _SoftSV_exception (void)
{

}

//*****************************************************************************************
//                              SysTick Interrupt Course
//*****************************************************************************************	
void __attribute__((interrupt)) _SysTick_exception (void)
{
	
}


/*****************************************************************************************
                              _CANFD6_exception Course
*****************************************************************************************/

void __attribute__((interrupt)) _CANFD7_exception (void)
{
	uint8_t Rmc_count = 0;
	Canfd_MailboxHeaderType Canfd_MailboxHeader_R = {0};
	Can_Controller_InterruptFlagType Can_Controller_InterruptFlag;
	volatile Kf32a_Canfd_Reg *ControllerRegPtr = (Kf32a_Canfd_Reg *)Can_m_ControllersInfo[CANfd7].BaseAddress;
	Can_m_FdGetIntFlag(CANfd7, &Can_Controller_InterruptFlag, &Rmc_count);
	Can_m_FdClearIntFlag(CANfd7, &Can_Controller_InterruptFlag, Rmc_count);
	fprintf(USART1_STREAM,"CAN INT IN!\r\n");
	if (Can_Controller_InterruptFlag.RxIntFlag == 0x01)
	{
//		fprintf(USART1_STREAM,"CAN INT IN!\r\n");
		if(Can_m_FdGetMailBoxState(CANfd7,Mailbox_1) == MAIL_RECEIVE_SUCCESS)
		{
			/* Read recevie mailbox information and reinitialize mailbox code */
			Can_m_FdMailBox_Read(CANfd7, Mailbox_1, &Canfd_MailboxHeader_R,MAIL_RECEIVE);//
			Receive_Flag++;
			fprintf(USART1_STREAM,"Mailbox_1 received!\r\n");
		}

		if(Can_m_FdGetMailBoxState(CANfd7,Mailbox_2) == MAIL_RECEIVE_SUCCESS)
		{
			/* Read recevie mailbox information and reinitialize mailbox code */
			Can_m_FdMailBox_Read(CANfd7, Mailbox_2, &Canfd_MailboxHeader_R,MAIL_RECEIVE);
			Receive_Flag++;
			fprintf(USART1_STREAM,"Mailbox_2 received!\r\n");
		}
	}
}



